﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
public partial class register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {


    }
    //创建用户后写入数据库
    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        
        string name = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName")).Text;
        string sex = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Sex")).SelectedItem.Text;
        int age = Convert.ToInt32(((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Age")).Text);
        string password = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Password")).Text;
        string question = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Question")).Text;
        string answer = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Answer")).Text;
        string adress = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Pro")).SelectedItem.Text +
                        ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("City")).SelectedItem.Text;
        string postcode = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Postcode")).Text;
        string tel = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Tel")).Text;
        string email = ((TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Email")).Text;
        DateTime datetime = DateTime.Now;
        Members merber = new Members();
        Roles.AddUserToRole(name, "Member");
        
        merber.assertMembers(name, sex, age, password, question, answer, adress, postcode, tel, email, datetime);
       
    }
    //省市下拉框的同步更新
    protected void Pro_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList pro=(DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("Pro");
        DropDownList citys=(DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("City");
        citys.Items.Clear();
        city cs = new city();
        var s = pro.SelectedItem;
        int id = Convert.ToInt32(s.Value);
        foreach (var c in cs.GetCityByProId(id))
        {
            citys.Items.Add(c.cityName);
            citys.Items.FindByText(c.cityName).Value = Convert.ToString(c.cityID);

        }
    }

}